import time
from itertools import repeat
from multiprocessing import Pool


def hi(name, age, msg):
    print(f'hello {name}, age {age}. {msg}')
    time.sleep(3)


def pool_test():
    names = ['tom', 'cat']
    ages = [1, 3]
    # 异步同时开始执行hi方法
    with Pool(2) as p:
        p.starmap(hi, zip(names, ages, repeat('how r u', 2)))


def zip_test():
    l1 = [1, 2, 3]
    l2 = [1, 2]
    z = zip(l1, l2)  # 对l1 和 l2 进行拼接为元组，index位相同的作为一个元组，元素个数为数组最小的长度
    print(*z)  # zip后是一个zip对象，通过*解包


if __name__ == '__main__':
    zip_test()
    pool_test()
